package com.chen.auth.controller;

import com.chen.auth.service.TokenService;
import com.chen.base.module.log.annotation.SysLog;
import com.chen.root.base.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.v3.oas.annotations.Operation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @description:
 * @Author C_Y_J
 * @create 2022/1/20 9:16
 **/
@RestController
@RequestMapping("/token")
@AllArgsConstructor
@Slf4j
@Api(value = "token",tags = "token端点api管理")
public class TokenEndpointController {

    private final TokenService tokenService;

    @PostMapping("/login")
    @Operation(summary = "登录",description = "登录")
    @SysLog("登录")
    public R login(@RequestParam Map<String,Object> map){
        return tokenService.login(map);
    }

    @DeleteMapping("/logout")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "authHeader",value = "Authorization中的token",dataType = "String",required = true)
    })
    @Operation(summary = "账号登出",description = "账号登出")
    @SysLog("登出")
    public R logout(@RequestHeader(value = HttpHeaders.AUTHORIZATION, required = false) String token) {
        return tokenService.logout(token);
    }

}
